/**
 * =================================================================
 * 版权所有 2011-2013 深圳市泰海网络科技服务有限公司，并保留所有权利
 * -----------------------------------------------------------------
 * 这不是一个自由软件！您不能在任何未经允许的前提下对程序代码进行修改和使用；
 * 不允许对程序代码以任何形式任何目的的再发布
 * =================================================================
 */
package com.imoney.payment.member.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.imoney.framework.base.entity.Response;
import com.imoney.framework.base.exception.ServiceException;
import com.imoney.payment.chain.HandlerChain;
import com.imoney.payment.member.common.InfoCode;
import com.imoney.payment.member.domain.Member;
import com.imoney.payment.member.domain.RegCompleteRequest;
import com.imoney.payment.member.domain.RegRequest;
import com.imoney.payment.member.handler.CheckEmailRepeatHandler;
import com.imoney.payment.member.handler.InitAccountHandler;
import com.imoney.payment.member.handler.MemberHandler;
import com.imoney.payment.member.handler.RegParamHandler;
import com.imoney.payment.member.service.IMemberMgrService;
import com.imoney.payment.member.service.IMemberService;

/**
 * 类说明：<br>
 * 
 * <p>
 * 详细描述：<br>
 * 
 * </p>
 * 
 * <pre>
 * ——————————————————————————————————————————————————————————————————
 * |		修改人		|		修改时间			|		修改原因
 * ——————————————————————————————————————————————————————————————————
 * |	zengxx 曾宪新	|		2013-6-22		|	
 * ——————————————————————————————————————————————————————————————————
 * </pre>
 * 
 * @author zengxx 曾宪新(Xavier.zeng)
 * 
 *         CreateDate: 2013-6-22
 */
@Service(value = "memberMgrService")
public class MemberMgrServiceImpl implements IMemberMgrService {

	@Resource
	private RegParamHandler regParamHandler;

	@Resource
	private CheckEmailRepeatHandler checkEmailRepeatHandler;

	@Resource
	private MemberHandler memberHandler;

	@Resource
	private InitAccountHandler initAccountHandler;

	@Resource
	private IMemberService memberService;

	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public Response<Member> register(RegRequest request) throws ServiceException {
		
		/** 业务处理返回结果 */
		Response<Member> response = new Response<Member>();

		/** 业务处理链 */
		HandlerChain<Member> chain = new HandlerChain<Member>();
		chain.addHandler(regParamHandler) // 入参验证
			.addHandler(checkEmailRepeatHandler) // 并发处理
			.addHandler(memberHandler); // 初始化会员信息

		chain.doHandler(chain, request, response); // 业务链开始执行
		
		/** 发送邮件/短信 */
		if (InfoCode.SUCCEED == response.getCode()) {
			
		}
		
		return response;
	}

	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public Response<Member> addMember(RegCompleteRequest request)
			throws ServiceException {
		/** 业务处理返回结果 */
		Response<Member> response = new Response<Member>();

		/** 业务处理链 */
		HandlerChain<Member> chain = new HandlerChain<Member>();
		chain.addHandler(regParamHandler) // 入参验证
			.addHandler(checkEmailRepeatHandler) // 并发处理
			.addHandler(memberHandler) // 初始化会员信息
			.addHandler(initAccountHandler); // 初始化账户信息

		chain.doHandler(chain, request, response); // 业务链开始执行

		return response;
	}

}
